package com.lagou.edu.pojo;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

/**
 * @author leonzhangxf
 */
@Data
public class ApiResponse<T> {

    /**
     * 1-success
     */
    @JsonProperty("code")
    private int code;

    @JsonProperty("message")
    private String message;

    @JsonProperty("data")
    private T data;

    public static <T> ApiResponse<T> newErr(int code, String msg) {
        ApiResponse<T> response = new ApiResponse<>();
        response.setCode(code);
        response.setMessage(msg);
        return response;
    }

    public static <T> ApiResponse<T> newSuccess(T data) {
        ApiResponse<T> response = new ApiResponse<>();
        response.setCode(1);
        response.setMessage("success");
        response.setData(data);
        return response;
    }
}
